package cn.bxc.job;

import cn.bxc.IOrderService;
import lombok.extern.slf4j.Slf4j;
import org.checkerframework.checker.units.qual.C;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * 定时检测超过30分钟未支付的订单
 * @author bxc
 * @date 2025/6/9 15:34
 **/
@Slf4j
@Component
public class TimeOutCloseOrderJob {
    @Resource
    private IOrderService orderService;


    @Scheduled(cron = "0 0/10 * * * ?") //每十分钟进行一次检查
    public void exec(){
        try {
            log.info("任务：超时30分钟订单关闭");
            List<String> orderIds = orderService.queryTimeoutCloseOrderList();
            if(orderIds == null || orderIds.isEmpty()){
                log.info("定时任务，超时30分钟订单关闭，暂无超时未支付任务 orderIds is null");
                return;
            }
            for (String orderId : orderIds) {
                boolean status = orderService.changeOrderClose(orderId);
                log.info("定时任务，超时30分钟订单关闭 OrderId:{} status:{}", orderId, status);
            }
        } catch (Exception e) {
            log.error("定时任务，超时15分钟订单关闭失败",e);
        }
    }
}
